package cn.study.eurekaserver.config;

import com.netflix.discovery.EurekaClientConfig;
import com.netflix.eureka.EurekaServerConfig;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
import org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration;
import org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
@AutoConfigureBefore(EurekaServerAutoConfiguration.class)
public class RemoteRegionConfig {

    @Bean
    @ConditionalOnMissingBean
    public EurekaServerConfig eurekaServerConfig(EurekaClientConfig clientConfig){
        EurekaServerConfigBean server = new EurekaServerConfigBean();
        if(clientConfig.shouldRegisterWithEureka()){
            server.setRegistrySyncRetries(3);
        }
        server.setRemoteRegionAppWhitelist(new HashMap<>());
        return server;
    }
}
